var AlertText = "Questions requiring a response are marked with an asterisk (*). \n\n";
var form=document.survey_content;

function setentertext(field, ftext){	
	if (ftext!="") {
	    field.value=1;
	}
	else{
		field.value=0;
	}
}

function setentered(field, fieldx, field_other){
	if(fieldx.checked == null || fieldx.checked == false){
		field.value=0;
	}
	else{
		field.value=1;
		if(field_other != "" && field_other != undefined){
			var other_field_input = document.getElementsByName(field_other);
			if (other_field_input.length>0){
				other_field_input[0].value="";
			}
		}
	}
}

function setsum(field,field1){
	if (field.value!=""){
		field1.value=parseFloat(field.value);
		if(field1.value!="NaN"){
			field.value=field1.value;
		}
	}
	else{
		field1.value="";
	}
}

function checkNumber(e, minLen, maxLen, minVal, maxVal, errorMsg){
	var v = parseFloat(e.value);
	if (isNaN(v) || e.value.length < minLen || e.value.length > maxLen || v < minVal || v > maxVal){
		alert(errorMsg);
		e.focus();  
		return false;
	}
	else{ 
		return true;
	}
}

function validate_required(field,alerttxt){
	with(field){
		if (value==null||value==""){
			alert(alerttxt); return false
		}
		else{
			return true
		}
	}
}

function setselected(field,fieldx,field_other){
	if (fieldx.value==null || fieldx.value==""){
		field.value=0;
	}
	else{
		field.value=1;
		if(field_other!=""&&field_other!=null){
			var other_field_input =document.getElementsByName(field_other);
			if (other_field_input.length>0){
				other_field_input[0].value="";
				var radio_field=document.getElementsByName(fieldx.name);
				if(radio_field.length>1){
					if (radio_field[1].checked!=false){
						radio_field[1].checked=false;
					}
				}
			}
		}
	}
}

function setselectedMatrix(field,fieldx){
	if(fieldx.value==null || fieldx.value==""){
		field.value=0;
	}
	else{
		field.value=1;
	}
}

function getfocus(id){
	document.getElementById("id"+id).focus();
}

function test_select(field,fieldx){
	var field_q=document.getElementsByName(fieldx);
	if(field_q.length>0){
		if (field_q[0].value==null || field_q[0].value==""){
			field.value=0;
		}
		else{
			field.value=1;
		}
		if(field_q[1].checked!=false){
			field_q[1].checked=false;
		}
	}
}

function test_radios(field,fieldx,number){
	var field_q=document.getElementsByName(fieldx);
	if (field_q.length>0){
		if(field_q[0].value==null || field_q[0].value==""){
			field.value=0;
		}
		else{
			field.value=1;
		}
		if(field_q[number].checked!=false){
			field_q[number].checked=false;
		}
	}
}

function change_selected(select_name){
	var selected_input=document.getElementsByName(select_name);
	if (selected_input.length>0){
		if (selected_input[0].selectedIndex!=0){
			selected_input[0].selectedIndex=0;
		}
		if (selected_input[1].checked!=true){
			selected_input[1].checked=true;
		}
	}
}

function change_checked(radio_name, number){
	var radios=document.getElementsByName(radio_name);
	radios[number].checked="true";
}
